$(function () {
    $("#page").load("/html/page.html");
});

function findAll() {
    let data = {
        name: $("#name").val(),
        leader: $("#leader").val(),
        startEstablishedTime: $("#startEstablishedTime").val(),
        endEstablishedTime: $("#endEstablishedTime").val(),
        pageSize: $.trim($("#pageSize").val()),
        pageNum: $.trim($("#pageNum").val()),
    }
    let result = myAjax('/g/group/findAll', "post", data)
    if (result.code === 200) {
        show(result.data.list);
        $("#pageCount").html(result.data.number);
    } else {
        layer.msg("查询失败");
    }
    ;

}

function show(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].leader==null){
            data[i].leader = "暂无数据";
        }
        html += '   <tr> ' +
            '  <td><input type="checkbox" name="isCheck" value="' + data[i].id + '">' + data[i].id + '</td>\n' +
            '        <td>' + data[i].name + '</td>\n' +
            '        <td>' + data[i].leader + '</td>\n' +
            '        <td>' + data[i].establishedTime + '</td>\n' +
            '        <td><input type="button" style="width: 80px;border-radius: 5px;' +
            'background-color: #e07731" value="查看成员" onclick="lookMember(' + data[i].id + ')">' +
            '         <input type="button" style="width: 80px;border-radius: 5px;' +
            'background-color: #2ca186" value="修改信息" onclick="edit(' + data[i].id + ',`' + data[i].name + '`)">' +
            '         <input type="button" style="width: 80px;border-radius: 5px;' +
            'background-color: #d0c34b" value="分配组员" onclick="compareMember(' + data[i].id + ')"></td>' +
            '    </tr>';
    }
    $("#findAll").html(html);
}

function lookMember(id) {
    sessionStorage.setItem("groupId", id);
    //弹出一个页面层
    layer.open({
        type: 2,
        anim: 3,
        title: '查看当前成员' ,
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/group/member.html', 'no'],
    })
}

function compareMember(id) {
    sessionStorage.setItem("groupId", id);
    //弹出一个页面层
    layer.open({
        type: 2,
        anim: 3,
        title: '分配小组成员' ,
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/group/compareMember.html', 'no'],
    })
}

//点击修改按钮进行页面弹出，传递两个参数，一个小组id一个小组名字，然后动态赋值给弹出页面，后面添加成员要用到。
layui.use('layer');

function edit(id, name) {
    sessionStorage.setItem("groupId", id);
    //弹出一个页面层
    let html = "<span id='group-name-edit'>" + name + "</span>"
    layer.open({
        type: 2,
        anim: 3,
        title: '编辑' + html + '',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/group/groupEdit.html', 'no'],
    })
}

function newAdd(title, url) {
    layer.open({
        type: 2,
        anim: 1,
        title: title,
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: [url, 'no'],
    })
}